package com.ujs.edu.medicine.dao;

import java.util.List;

import com.ujs.edu.medicine.dataobject.YunjiayiShop;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
@Mapper
public interface YunjiayiShopMapper {
    @Delete({
            "delete from yunjiayi_shop",
            "where shopId = #{shopid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer shopid);

    @Insert({
            "insert into yunjiayi_shop (shopId, description, ",
            "address, shopname, ",
            "telephone, shopImage, ",
            "shopgrade, inideliveryfee, ",
            "deliveryfee, iscollect)",
            "values (#{shopid,jdbcType=INTEGER}, #{description,jdbcType=VARCHAR}, ",
            "#{address,jdbcType=VARCHAR}, #{shopname,jdbcType=VARCHAR}, ",
            "#{telephone,jdbcType=VARCHAR}, #{shopimage,jdbcType=VARCHAR}, ",
            "#{shopgrade,jdbcType=REAL}, #{inideliveryfee,jdbcType=REAL}, ",
            "#{deliveryfee,jdbcType=REAL}, #{iscollect,jdbcType=VARCHAR})"
    })
    @Options(useGeneratedKeys = true,keyProperty = "shopid",keyColumn = "shopId")
    int insert(YunjiayiShop record);

    @Select({
            "select",
            "shopId, description, address, shopname, telephone, shopImage, shopgrade, inideliveryfee, ",
            "deliveryfee, iscollect",
            "from yunjiayi_shop",
            "where shopId = #{shopid,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column="shopId", property="shopid", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
            @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
            @Result(column="shopname", property="shopname", jdbcType=JdbcType.VARCHAR),
            @Result(column="telephone", property="telephone", jdbcType=JdbcType.VARCHAR),
            @Result(column="shopImage", property="shopimage", jdbcType=JdbcType.VARCHAR),
            @Result(column="shopgrade", property="shopgrade", jdbcType=JdbcType.REAL),
            @Result(column="inideliveryfee", property="inideliveryfee", jdbcType=JdbcType.REAL),
            @Result(column="deliveryfee", property="deliveryfee", jdbcType=JdbcType.REAL),
            @Result(column="iscollect", property="iscollect", jdbcType=JdbcType.VARCHAR)
    })
    YunjiayiShop selectByPrimaryKey(Integer shopid);

    @Select({
            "select",
            "shopId, description, address, shopname, telephone, shopImage, shopgrade, inideliveryfee, ",
            "deliveryfee, iscollect",
            "from yunjiayi_shop"
    })
    @Results(id="shopMap",value = {
            @Result(column="shopId", property="shopid", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
            @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
            @Result(column="shopname", property="shopname", jdbcType=JdbcType.VARCHAR),
            @Result(column="telephone", property="telephone", jdbcType=JdbcType.VARCHAR),
            @Result(column="shopImage", property="shopimage", jdbcType=JdbcType.VARCHAR),
            @Result(column="shopgrade", property="shopgrade", jdbcType=JdbcType.REAL),
            @Result(column="inideliveryfee", property="inideliveryfee", jdbcType=JdbcType.REAL),
            @Result(column="deliveryfee", property="deliveryfee", jdbcType=JdbcType.REAL),
            @Result(column="iscollect", property="iscollect", jdbcType=JdbcType.VARCHAR)
    })
    List<YunjiayiShop> selectAll();

    /*模糊搜索*/
    @Select("select * from yunjiayi_shop where shopname like '%${shopname}%'")
    @ResultMap("shopMap")
    List<YunjiayiShop> selectLike(@Param("shopname")String shopname);

    @Update({
            "update yunjiayi_shop",
            "set description = #{description,jdbcType=VARCHAR},",
            "address = #{address,jdbcType=VARCHAR},",
            "shopname = #{shopname,jdbcType=VARCHAR},",
            "telephone = #{telephone,jdbcType=VARCHAR},",
            "shopImage = #{shopimage,jdbcType=VARCHAR},",
            "shopgrade = #{shopgrade,jdbcType=REAL},",
            "inideliveryfee = #{inideliveryfee,jdbcType=REAL},",
            "deliveryfee = #{deliveryfee,jdbcType=REAL},",
            "iscollect = #{iscollect,jdbcType=VARCHAR}",
            "where shopId = #{shopid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(YunjiayiShop record);

    /*通过药店名称查询*/
    @Select("select * from yunjiayi_shop where shopname=#{shopname}")
    @ResultMap("shopMap")
    YunjiayiShop selectByShopName(@Param("shopname")String shopname);


    @Select("select avg(shopgrade) from yunjiayi_shop")
    @ResultMap("shopMap")
    int getAvgshopgrade();

    /*模糊查询*/
    @Select("select * from yunjiayi_shop where shopname like '%${shopname}%'")
    List<YunjiayiShop> selectShopLike(@Param("shopname") String shopname);

}